const cities = []
const position = getQueryString('position')
// 初始化swiper
var mySwiper = new Swiper ('.swiper-container', {
    // direction: '',
    loop: true,
    autoplay: true,
    // 如果需要分页器
    pagination: {
        el: '.swiper-pagination',
    },

    // 如果需要前进后退按钮
    navigation: {
        nextEl: '.swiper-button-next',
        prevEl: '.swiper-button-prev',
    }
})
function deleteCity(item) {
    cities.splice($.inArray(item, cities), 1)
    refresh()
}
function openDescrip(item) {
    $(item).next().slideToggle()
    $(item).find('i').toggleClass('open')
}
function show() {
    $('.full-screen').show()
}
//去除筛选条件
function refresh() {
    for (let key in positionList4Internship) {
        // 循环添加数据
        let data = positionList4Internship[key]
        let str = ''
        data.map(function (temp) {
            if ((!position || temp.name.indexOf(position) >= 0) && (cities.length === 0 || $.inArray(temp.pos, cities) >= 0)) {
                str += '<div class="item-wrap"><div class="item item-content" onclick="openDescrip(this)"><span>' + temp.name +'</span><span>' + temp.pos + '</span><span>' + temp.num + '</span><span>' + temp.salary + '</span><i></i></div><div class="item-descrip"><p class="descrip-head">岗位职责</p>'
                temp.duty.map(function (item) {
                    str += '<p class="descrip">' + item + '</p>'
                })
                str += '<p class="descrip-head">任职要求</p>'
                temp.request.map(function (item) {
                    str += '<p class="descrip">' + item + '</p>'
                })
                str += '<button onclick="show()">立即申请</button></div></div>'
            }
        })
        $('#' + key + ' .items').html(str)
    }
    let str = ''
    cities.map(function (item) {
        let temp = "'" + item + "'"
        str += '<div class="chose-item"><label>' + item + '</label><i onclick="deleteCity(' + temp + ')">+</i></div>'
    })
    $('.chose-list').html(str)
}
$(document).ready(function () {
    // 数据刷新
    refresh()
    // 筛选岗位
    $('.pos-item').click(function () {
        let name = $(this).html()
        if ($.inArray(name, cities) < 0) {
            cities.push(name)
            refresh()
        }
    })
    $('.down-load > img').click(function () {
        $('.full-screen').hide()
    })
})